﻿@inherits AdminCompontentBase
<div class="message-template-items">
    <MDataTable Headers="_headers"
                Items="Value"
                HideDefaultFooter>
        <TopContent>
            <MToolbar Flat>
                <MToolbarTitle Class="subtitle3 regular--text pa-0">@T("DisplayName.MessageTemplateItem")</MToolbarTitle>
                <MDialog @bind-Value="_dialog"
                         MaxWidth="500">
                    <MCard>
                        <MCardTitle>
                            <span class="text-h6">@FormTitle</span>
                        </MCardTitle>

                        <MCardText>
                            <MContainer>
                                <MRow Class="row-box">
                                    <MCol Cols="12"
                                          Sm="6"
                                          Md="4">
                                        <MTextField @bind-Value="_editedItem.Code"
                                                    Label="@T("DisplayName.MessageTemplateItemCode")"></MTextField>
                                    </MCol>
                                    <MCol Cols="12"
                                          Sm="6"
                                          Md="4">
                                        <MTextField @bind-Value="_editedItem.MappingCode"
                                                    Readonly
                                                    Label="@T("DisplayName.MessageTemplateItemMappingCode")"></MTextField>
                                    </MCol>
                                    <MCol Cols="12"
                                          Sm="6"
                                          Md="4">
                                        <MTextField @bind-Value="_editedItem.DisplayText"
                                                    Label="@T("DisplayName.MessageTemplateItemDisplayText")"></MTextField>
                                    </MCol>
                                </MRow>
                            </MContainer>
                        </MCardText>

                        <MCardActions>
                            <MSpacer></MSpacer>
                            <SButton Color="blue darken-1"
                                     Text
                                     OnClick="Close">
                                @T("Cancel")
                            </SButton>
                            <SButton Color="blue darken-1"
                                     Text
                                     OnClick="SaveAsync">
                                @T("Save")
                            </SButton>
                        </MCardActions>
                    </MCard>
                </MDialog>
            </MToolbar>
        </TopContent>
        <ItemColContent>
            @switch (context.Header.Value)
            {
                case (nameof(MessageTemplateItemDto.Code)):
                    if (Value.IndexOf(context.Item) == _editedIndex)
                    {
                            <MTextField Class="mr-6" @bind-Value="_editedItem.Code" Dense Outlined HideDetails="@("auto")" Attributes="@(new Dictionary<string,object>{["maxLength"]=16})"></MTextField>
                    }
                    else
                    {
                        <div class="text-truncate mr-6" style="max-width:172px">@context.Value</div>
                    }
                    break;
                case (nameof(MessageTemplateItemDto.DisplayText)):
                    if (Value.IndexOf(context.Item)==_editedIndex)
                    {
                        <MTextField @bind-Value="_editedItem.DisplayText" Dense Outlined HideDetails="@("auto")" Attributes="@(new Dictionary<string,object>{["maxLength"]=128})"></MTextField>
                    }
                    else
                    {
                        <div class="text-truncate" style="max-width:172px">@context.Value</div>
                    }
                    break;
                case "actions":
                    if (Value.IndexOf(context.Item)==_editedIndex)
                    {
                        <div class="d-flex">
                            <MButton Small Icon OnClick="CloseDelete">
                                <SIcon Small Color="warning" Tooltip="@T("Cancel")">mdi-close</SIcon>
                            </MButton>
                            <MButton Small Class="ml-6" Icon OnClick="SaveAsync">
                                <SIcon Small Color="green">mdi-check</SIcon>
                            </MButton>
                        </div>
                    }
                    else
                    {
                        <MButton Small Class="mr-4" Icon OnClick="()=>EditItem(context.Item)">
                            <SIcon Small Color="green">mdi-pencil</SIcon>
                        </MButton>
                    }
                    break;
                default:
                    <div class="text-truncate mr-6" style="max-width:172px">@context.Value</div>
                    break;
            }
        </ItemColContent>
    </MDataTable>
</div>